/**
 * Copyright 2010-2011 Nicholas Blair, Eric Dalquist
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.googlecode.ehcache.annotations;

import java.lang.reflect.Method;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import net.sf.ehcache.constructs.blocking.SelfPopulatingCache;

/**
 * Defines the type of cache decorator that will be added to the cache as it is
 * iteracted with from the cache interceptor
 * 
 * @author Eric Dalquist
 * @version $Revision: 656 $
 */
public enum DecoratedCacheType {
    /**
     * No decorator
     */
    NONE,
    /**
     * Use {@link SelfPopulatingCache}
     */
    SELF_POPULATING_CACHE,
    /**
     * Use {@link RefreshingSelfPopulatingCache}
     */
    REFRESHING_SELF_POPULATING_CACHE;
    
    private static final Logger LOGGER = LoggerFactory.getLogger(DecoratedCacheType.class);
    
    /**
     * Determine the DecoratedCacheType for the cacheable annotation
     */
    public static DecoratedCacheType getDecoratedCacheType(Cacheable ann, Method method) {
        @SuppressWarnings("deprecation")
        final boolean selfPopulating = ann.selfPopulating();
        final DecoratedCacheType decoratedCacheType = ann.decoratedCacheType();
        if (selfPopulating) {
            if (decoratedCacheType != DecoratedCacheType.NONE) {
                LOGGER.warn("selfPopulating is set to true and decoratedCacheType is set to " + decoratedCacheType + ", selfPopulating will be ignored on: " + method);
            }
            else {
                return DecoratedCacheType.SELF_POPULATING_CACHE;
            }
        }
        
        return decoratedCacheType;
    }
}
